<?php
namespace app\api\controller;

use app\api\model\Beauty as BeautyModel;
use think\Db;

class Beauty
{

    //  查询一条数据详情
    public function getID($id)
    {

        $result = Db::name('Beauty')
            ->where('id', $id)
            ->find();
        return $res = array(
            'code' => '200',
            'data' => $result,
            'msg' => '成功',
        );
    }

    public function Delete($id)
    {

        $result = Db::name('Beauty')
            ->where('id', $id)
            ->delete();
        return $res = array(
            'code' => '200',
            'data' => $result,
            'msg' => '成功',
        );
    }
    // 修改
    public function BeautyEdit($id)
    {

        $by = BeautyModel::get($id);
        if (!$_POST) {

            return $res = array(
                'code' => '202',
                'msg' => '搞事情阿',
            );
        } else {

            $by['BeautyTitle'] = $_POST['BeautyTitle'];
            $by['Beautyper'] = $_POST['Beautyper'];
            $by['BeautyTime'] = $_POST['BeautyTime'];
            $by['BeautyType'] = $_POST['BeautyType'];
            $by['BeautyContent'] = $_POST['BeautyContent'];
            if ($by->save()) {
                return $res = array(
                    'code' => '200',
                    'msg' => '成功',
                );
            } else {

                return $res = array(
                    'code' => '201',
                    'msg' => '失败',
                );
            }
        }

    }

    // 添加
    public function add()
    {

        $by = new BeautyModel;
        if (!$_POST) {

            return $res = array(
                'code' => '202',
                'msg' => '搞事情阿',
            );
        } else {

            $by['BeautyTitle'] = $_POST['BeautyTitle'];
            $by['Beautyper'] = $_POST['Beautyper'];
            $by['BeautyTime'] = $_POST['BeautyTime'];
            $by['BeautyType'] = $_POST['BeautyType'];
            $by['BeautyContent'] = $_POST['BeautyContent'];
            $by['id'] = strtotime(date('Y-m-d H:i:s'));

            if ($by->save()) {

                return $res = array(
                    'code' => '200',
                    'msg' => '添加成功',
                );

            } else {
                return $res = array(
                    'code' => '201',
                    'msg' => '添加失败',
                );
            }
        }
    }

    //列表
    public function Beautylist()
    {

        $list = Db::name('Beauty')
            ->select();
        return array(
            'code' => 200,
            'msg' => 'ok',
            'Relust' => ($list),
        );

    }

}
